<!--
 * @Description: 
 * @Date: 2024-01-26 14:53:41
 * @LastEditTime: 2024-02-19 16:19:12
-->
<template>
  <div class="mySuggest">
    <el-tabs v-model="activeName" @tab-click="handleClick">
      <el-tab-pane label="领衔建议" name="first"></el-tab-pane>
      <el-tab-pane label="附议建议" name="second"></el-tab-pane>
      <el-tab-pane label="全部建议" name="third"></el-tab-pane>
    </el-tabs>
    <el-table
      v-loading="loading"
      border
      :data="suggestList"
      style="width: 100%"
    >
      <!-- <el-table-column prop="suggestInfo.suId" label="建议号" align="center"> -->
      <!-- </el-table-column> -->
      <el-table-column
        prop="suggestInfo.title"
        label="题目"
        align="center"
        :show-overflow-tooltip="true"
      >
      </el-table-column>
      <el-table-column prop="address" label="承办单位" align="center">
        <template slot-scope="scope">
          {{ scope.row.deptId ? scope.row.deptUser.nickName : "暂无" }}
        </template>
      </el-table-column>
      <el-table-column
        prop="address"
        label="代表团"
        align="center"
        width="120px"
      >
        <template slot-scope="scope">
          {{
            scope.row.suggestInfo.leaderUser.deId | delegation(delegationList)
          }}
        </template>
      </el-table-column>
      <el-table-column label="领衔代表" align="center" width="120px">
        <template slot-scope="scope">
          {{ scope.row.suggestInfo.leaderUser.userName }}
        </template>
      </el-table-column>

      <el-table-column prop="status" label="状态" align="center" width="120px">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.sys_suggest_status"
            :value="scope.row.status"
          />
        </template>
      </el-table-column>
      <el-table-column prop="address" align="center" label="操作" width="200px">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleSkip(scope.row)"
            v-hasPermi="['suggest:mySuggest:info']"
            >查看详情</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {
  getProcessInfoList,
  getListAll,
  getListMyOf,
} from "@/api/suggest/index";
import { addDelegationList } from "@/api/dbxx/dbxxgroup/index";
import { mapGetters } from "vuex";
export default {
  name: "mySuggest",
  dicts: ["sys_suggest_status"],
  computed: {
    ...mapGetters(["userId"]),
  },
  data() {
    return {
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      total: 0,
      loading: false,
      delegationList: [],
      suggestList: [],
      activeName: "first",
    };
  },
  filters: {
    delegation(value, delegationList) {
      return delegationList.filter((item) => item?.deId == value)[0]?.name;
    },
  },
  created() {
    //获取代表团列表
    addDelegationList().then((response) => {
      this.delegationList = response.rows;
    });
    this.getList();
  },
  methods: {
    /**
     * @description: 根据不同的tab 分别获取领衔，附议，全部
     * @return {*}
     */
    getList() {
      this.loading = true;
      switch (this.activeName) {
        //领衔建议列表
        case "first":
          getListMyOf({ ...this.queryParams, leaderId: this.userId }).then(
            (res) => {
              this.suggestList = res.rows;
              this.total = res.total;
              this.loading = false;
            }
          );
          break;
        //附议建议列表
        case "second":
          getListMyOf({ ...this.queryParams, followerId: this.userId }).then(
            (res) => {
              this.suggestList = res.rows;
              this.total = res.total;
              this.loading = false;
            }
          );
          break;
        //全部建议列表
        case "third":
          getListAll({ ...this.queryParams, id: this.userId }).then((res) => {
            this.suggestList = res.rows;
            this.total = res.total;
            this.loading = false;
          });
          break;
        default:
          break;
      }
    },
    /**
     * @description: tab切换
     * @param {*} tab
     * @param {*} event
     * @return {*}
     */
    handleClick(tab, event) {
      this.getList();
    },
    /**
     * @description:  查看详情
     * @param {*} row
     * @return {*}
     */
    handleSkip(row) {
      this.$router.push({
        path: "/suggest/suggestInfo",
        query: {
          proId: row.proId,
          type: "readOnly",
        },
      });
    },
    /**
     * @description: 详情跳转
     * @param {*} row
     * @return {*}
     */
    handleSkip(row) {
      this.$router.push({
        path: "/suggest/suggestInfo",
        query: {
          proId: row.proId,
          type: "readOnly",
        },
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.mySuggest {
  padding: 20px;
}
</style>
